import redis

# 连接数据库
r = redis.StrictRedis(host='127.0.0.1', port=6379, db=0, decode_responses=True, password='123456')

# 设置
print(r.set('name', 'lucky'))

# 获取
print(r.get('name'))

# 关闭连接
r.close()